package com.linln.proxy.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
    private static Logger logger = LoggerFactory.getLogger(DateUtils.class);
    public static String getCurrentDate(){
        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(dt);
    }

    public static String getCurrentTime(){
        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(dt);
    }

    public static String getNextDate(){
        Calendar calendar = Calendar.getInstance(); // 获取当前日期
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_YEAR, 1); // 加一天
        Date nextDay = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(nextDay);
    }

    public static String getNextTime(){
        Calendar calendar = Calendar.getInstance(); // 获取当前日期
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_YEAR, 1); // 加一天
        return String.valueOf(calendar.getTime().getTime());
    }

    public static String getCurrentHourTime(){
        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        return sdf.format(dt);
    }

    public static String getOccDate(){
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE,7);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(cal.getTime());
    }

    public static String getIngoOccDate() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE,8);
        if(cal.get(Calendar.DAY_OF_WEEK)==2){
            cal.add(Calendar.DATE,1);
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(cal.getTime());
    }

    //获取执行日期
    public static String getExeDate(String dpDt)  {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dt = null;
        try {
            dt = sdf.parse(dpDt);
            Calendar cal = Calendar.getInstance();
            cal.setTime(dt);
            cal.add(Calendar.DATE,-7);
            return sdf.format(cal.getTime());
        } catch (ParseException e) {
            logger.error("转换执行日期报错:",e);
            return null;
        }
    }

    public static void main(String[] args) {
        System.out.println(getIngoOccDate());
    }
}
